import request from './request'
export class ApiService {
    constructor(url) {
        this.baseUrl = url;
    }
    //构建多级目录
    build(url) {
        this.baseUrl = this.baseUrl+url;
    }

    //获取列表数据
    list(query) {
        return request({
            url: this.baseUrl + '/list',
            method: 'get',
            params: query
        })
    }

    //新增数据
    create(data) {
        return request({
            url: this.baseUrl,
            method: 'post',
            data: data
        })
    }
    //查询数据
    search(data) {
        return request({
            url:this.baseUrl,
            method:'post',
            data:data
        })
    }

    //修改数据
    update(data) {
        return request({
            url: this.baseUrl + '/update',
            method: 'put',
            data: data
        })
    }

    //删除数据
    delete(id) {
        return request({
            url: this.baseUrl + '/' + id,
            method: 'delete'
        })
    }

    //获取数据详情
    getViewById(id) {
        return request({
            url: this.baseUrl + '/' + id,
            method: 'get'
        })
    }
    //获取数据
    getViewList() {
        return request({
            url: this.baseUrl,
            method: 'get'
        })
    }
    //发送post请求
    post(data) {
        return request({
            url:this.baseUrl,
            method:'post',
            data: data,
        })
    }
    //发送get请求
    get(id) {
        return request({
            url:this.baseUrl,
            method:"get",
            param:id,
        })
    }
    //发送get请求
    getParams(params) {
        return request({
            url:this.baseUrl,
            method:"get",
            params:params,
        })
    }
    //获取cookie
   getCookie(cname)
    {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for(var i=0; i<ca.length; i++)
        {
            var c = ca[i].trim();
            if (c.indexOf(name)==0) return c.substring(name.length,c.length);
        }
        return "";
    }

}
